using QFramework;
using QGameFramework.Enums;
using UnityEngine;

namespace QGameFramework.QProcedure
{
    public class ProcedureComponent : BaseComponent
    {
        /// <summary>
        /// 流程状态机
        /// </summary>
        public FSM<States> ProcedureFSM = new FSM<States>();

        /// <summary>
        /// 初始化
        /// </summary>
        public override void OnInit()
        {
            base.OnInit();

            ProcedureFSM.AddState(States.Init, new InitState(ProcedureFSM, this));
            ProcedureFSM.AddState(States.Preload, new PreloadState(ProcedureFSM, this));
            ProcedureFSM.AddState(States.Verify, new VerifyState(ProcedureFSM, this));
            ProcedureFSM.AddState(States.CheckVersion, new CheckVersionState(ProcedureFSM, this));
            ProcedureFSM.AddState(States.UpdateVersion, new UpdateVersionState(ProcedureFSM, this));
            ProcedureFSM.AddState(States.LogIn, new LogInState(ProcedureFSM, this));
            ProcedureFSM.AddState(States.Gaming, new GamingState(ProcedureFSM, this));

            LogKit.I("Procedure 组件初始化");
            ProcedureFSM.StartState(States.Init);
        }

        /// <summary>
        /// 更新逻辑
        /// </summary>
        private void Update()
        {
            //更新子状态机逻辑
            ProcedureFSM.Update();
        }

#if UNITY_EDITOR
        /// <summary>
        /// 编辑器模式显示调试信息
        /// </summary>
        private void OnGUI()
        {
            ProcedureFSM.OnGUI();
            GUIStyle myStyle = new GUIStyle();
            myStyle.fontSize = 30; // 更改字体大小为30
            myStyle.normal.textColor = Color.green; // 更改字体颜色为红色

            // 设置文字的位置和大小
            Rect rect = new Rect(10, 10, 300, 60); // 注意：我们需要将高度增大以适应更大的字体

            // 显示带有样式的文字
            GUI.Label(rect, ProcedureFSM.CurrentStateId.ToString(), myStyle);
        }
#endif
    }
}